package app.server.project.cloud.random.service;

import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class EmailService {



    @Autowired
    private JavaMailSender javaMailSender;
    @Value("${spring.mail.username}")
    private String sysEmail;

    public void sendCode(String email,String code){
        log.info("邮箱:{}发送:{}",email,code);
        this.sendSimpleMessage(email,"几何物联验证码",code);
    }

    private void sendSimpleMessage(String to, String subject, String text) {
        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom(this.sysEmail); // 发件人邮箱地址
        message.setTo(to); // 收件人邮箱地址
        message.setSubject(subject); // 邮件主题
        message.setText(text); // 邮件内容
        javaMailSender.send(message); // 发送邮件
    }
}
